﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace lapinou_game2
{
    class Weapon
    {
        ContentManager content;
        GraphicsDeviceManager graphics;
        Vector2 poslapin;

        Cursor cursor;
        Vector2 posCursor;

        // Donnees pour le curseur
        Vector2 unit = Vector2.Zero;
        Double distance;
        Vector2 equation; // equation de la droite formee par les deux points poslapin et posCurseur
        Vector2 unit_cursor; 
               

        int dMax; // rayon max du cercle autour du Lapin


        public Weapon(ContentManager Content, Vector2 posLapin, GraphicsDeviceManager Graphics, Cursor Cursor, Vector2 PosCursor)
        {
            dMax = 200;
            poslapin = posLapin;
            content = Content;
            graphics = Graphics ;
            cursor = Cursor;
            posCursor = PosCursor;
        }

        public void LoadContent()
        {

        }

        public Vector2 Normalization()
        {
            // determination de l'equation ax + b
            // a => equation.X 
            // b => equation.Y
            equation.X = (poslapin.Y - posCursor.Y) / (poslapin.X - posCursor.X);
            equation.Y = (poslapin.X * posCursor.Y - poslapin.Y * posCursor.X)/(poslapin.X - posCursor.X);

            //Determination de X (point d'intersection entre le cercle et la droite)            
            // /!\ equation de porc !
            
            unit_cursor.X = ((poslapin.X - posCursor.X)*(
                (float)Math.Sqrt(Convert.ToDouble((cursor.getPos().X - poslapin.X) *
                (cursor.getPos().X - poslapin.X) + (cursor.getPos().Y - poslapin.Y) *
                (cursor.getPos().Y - poslapin.Y))) - dMax - equation.Y))/(poslapin.Y - posCursor.Y);

            // Determiner Y
            unit_cursor.Y = equation.X * unit_cursor.X + equation.Y;

            return unit_cursor;

        }

        //public float Distance(Vector2 pointA, Vector2 pointB)
        //{

        //}

        public void UpDate()
        {
            distance = Math.Sqrt(Convert.ToDouble((cursor.getPos().X - poslapin.X) * (cursor.getPos().X - poslapin.X) + (cursor.getPos().Y - poslapin.Y) * (cursor.getPos().Y - poslapin.Y)));
            unit_cursor = Normalization();
             /*if (distance > dMax)
            {
                
                cursor.moveCursorCoord(Normalization());
                
            }      
            */
            
        }

        public void Draw(SpriteBatch sb)
        {
        }


    }
}
